package com.oauth.facebook.client.ui.tabs;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.components.client.rpc.OAuthAsnyCallBack;
import com.oauth.facebook.client.rpc.FacebookRemoteServiceAsync;
import com.rapwaves.feeds.FeedEngine;
import com.rapwaves.feeds.Feeds;

public class ProfileUpdatesTab extends Composite {

	private static MyConnectionsTabUiBinder uiBinder = GWT.create(MyConnectionsTabUiBinder.class);

	interface MyConnectionsTabUiBinder extends UiBinder<Widget, ProfileUpdatesTab> {
	}

	@UiField
	VerticalPanel connectionsPanel;

	@UiField
	DeckPanel deckPanel;

	public ProfileUpdatesTab() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public void init() {
		deckPanel.showWidget(0);

		connectionsPanel.clear();

		FacebookRemoteServiceAsync.INSTANCE.getFeeds(new OAuthAsnyCallBack<Feeds>() {

			@Override
			public void onSuccess(Feeds pResult) {
				if (pResult.getCount() == 0) {
					connectionsPanel.add(new Label("You don't have any updates"));
				} else {
					connectionsPanel.add(FeedEngine.getWidget(pResult));
				}
				deckPanel.showWidget(1);
			}
		});

	}
}
